const app = getApp();
const https = require('../../utils/https');
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    position_list: [],
    report_txt_num: '',
    check_time: '',
    inspector_name: '',
    house_register: '',
    check_end_time: '',
    position_list: '',
    order_sn: '',
    app_name: '',
    check_by: '',
    tel: '',
    app_ewm: '',
    kh: '',
    loading: false,
    disabled: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this,
      is_login_inspector = wx.getStorageSync('is_login_inspector');
    if (!is_login_inspector || is_login_inspector != 1) {
      wx.showToast({
        title: '请先登陆验房师账号',
        icon: 'none',
        duration: 1500
      })
      wx.redirectTo({
        url: '/pages/my/my',
      })
      return false;
    }
    if (options && options.order_sn != '') {
      that.setData({
        order_sn: options.order_sn
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      loading: false,
      disabled: false
    })
    this.getReportInfo();
  },
  /**
   * @xk 获取生成报告的相关信息
   * @param {} res 
   */
  getReportInfo: function(res){
    var that = this,
       order_sn = this.data.order_sn;
    https.post('getReportInfo',{order_sn: order_sn},true,'加载中').then(res=>{
      that.setData({
        report_txt_num: res.reportTextNum,
        check_time: res.check_time,
        inspector_name: res.inspector_name,
        house_register: res.house_register,
        check_end_time: res.check_end_time,
        position_list: res.position_list,
        check_by: res.check_by,
        app_name: res.app_name,
        tel: res.tel,
        app_ewm: res.app_ewm,
        kh: res.kh
      })
    })
  },

  /**
   * @xk 生成验房报告
   */
  createReport: function(){
    var that = this,
        order_sn = this.data.order_sn;
    that.setData({
      loading: true,
      disabled: true
    })
    https.post('createReport',{order_sn: order_sn},false,'正在生成报告').then(res=>{
      setTimeout(() => {
        wx.navigateTo({
          url: '/pages/inspection_viewreport/viewreport?order_sn='+order_sn,
        })
      }, 1500);
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow();
  },
})